<template>

  <div id="header_menu">
    <div class="header_right">
     

      <!-- <el-popover
        placement="bottom"
        width="96"
        trigger="click"
        popper-append-to-body="false"
        popper-class="my-popper1"
        content="个人中心"
      >
        
      </el-popover> -->

      <div class="user_info" @click="toUserInfo()">
        <el-avatar
          class="avatar"
          :src="$imageUrl  + avatarUrl"
        ></el-avatar>
        <span class="name">{{ loginName }}</span>
      </div>
      <template>
        <el-popconfirm
          icon-color="red"
          icon="el-icon-warning"
          title="确定退出登录吗？"
          popper-append-to-body="false"
          popper-class="my-popper"
          style="display: inline-block; vertical-align: top"
          @confirm="edit()"
        >
          <i slot="reference" class="el-icon-switch-button edit"></i>
        </el-popconfirm>
      </template>
    </div>
  </div>
</template>

<script>
export default {
  name: "header-menu",
  data() {
    return {
      path: {
        url: "/userInfo",
        name: "userInfo",
        title: "个人中心",
      },
      avatarUrl: window.sessionStorage.getItem("avatarUrl"),
      loginName: window.sessionStorage.getItem("loginName"),
    };
  },
  methods: {
    //退出登录
    edit() {
      this.$axios({
        method: "get",
        url: "/logout",
        headers: {
          "Content-Type": "application/x-www-form-urlencoded",
        },
      }).then((res) => {
        if (res.data.flag == true) {
          this.$router.push("/");
          window.sessionStorage.clear();
          //vuex的消息删掉
          
        } else {
          this.$message.warning("退出失败");
        }
      });
    },
    //个人信息
    toUserInfo() {
      // 通过vuex将数据存储在store中
      this.$store.commit("mutationSelectTags", this.path);
      this.$router.push("/userInfo");
    },
  },
};
</script>

<style lang="less"  scoped>
.header_right {
  float: right;
  height: 100%;
  line-height: 60px;

}
.avatar {
  height: 40px;
  margin-top: 10px;
  width: 40px;
}
.name {
  line-height: 60px;
  height: 60px;
  display: inline-block;
  vertical-align: top;
  margin-left: 10px;
}
.edit {
  width: 40px;
  line-height: 60px;
  height: 40px;
  display: inline-block;
  vertical-align: top;
  margin-left: 45px;
}
/deep/.el-icon-switch-button:before {
  font-size: 20px;
}
.my-popper {
  box-shadow: 0px 2px 10px 0px rgba(51, 70, 84, 0.2);
  .el-popconfirm__main {
    width: 100%;
    height: 22px;
    font-size: 14px;
    font-weight: 500;
    text-align: left;
    color: #333333;
    line-height: 22px;
    margin: 10px 0 12px 0;
    padding-left: 9px;
    .el-icon-warning:before {
      font-size: 18px;
    }
  }

  .el-popconfirm__action {
    display: flex;
    align-items: flex-start;
    padding-left: 10px;
    // 交换 确定 和 取消 按钮的位置
    .el-button:nth-child(1) {
      width: 60px;
      height: 28px;
      background: #ffffff;
      border: 1px solid rgba(33, 196, 145, 1);
      color: rgba(33, 196, 145, 1);
      border-radius: 6px;
      text-align: center;
    }
    .el-button:nth-child(2) {
      width: 60px;
      height: 28px;
      border: none;
      background: rgba(33, 196, 145, 1);
      border-radius: 6px;
      text-align: center;
    }
  }
}
.user_info {
  height: 60px;
  display: inline-block;
}
.my-popper1 {
  top: 46px;
  min-width: 96px;
}
</style>